#pragma once
#include <sys/types.h> //off_t
#include <memory> //shared_ptr
#include <string>
#include <cstdint> // 包含 uint32_t 的定义
#include "easylogging++.h"
#include <unistd.h>  // 包含 close 的声明
#define _mem_name "/TankInitStat"
#define IN
#define OUT

enum class TankStatus : uint32_t
{
    TANK_ON           = 0,
    TANK_OFF          = 1,
    TANK_SELF_RESTART = 2,
    TANK_UNSET        = 99
};

class TankStatusFuncs
{
private:
    off_t m_mem_size;
    static TankStatus real_tank_stat;
    static std::string m_shared_mem_name;
private:
    bool OpenSharedMemory(std::shared_ptr<int> OUT fd, const IN std::string & shared_mem_name);
    bool GetSharedMemoryObjectSize(const std::shared_ptr<int> IN fd, std::shared_ptr<off_t> OUT memSize);
    bool CreateSharedMemory(std::shared_ptr<int> OUT fd , const std::string IN & shared_mem_name);
    bool SetSharedMemoryObjectSize(const std::shared_ptr<int> IN fd , off_t IN mem_size,  const std::string IN & shared_mem_name);
    bool MappingSharedMemoryObjects(const std::shared_ptr<int> IN fd , off_t IN mem_size,  const std::string IN & shared_mem_name, void ** OUT ptr);
public:
    bool ReadTankStatusByMem(std::shared_ptr<TankStatus> OUT stat, const std::string IN _shared_mem_name = m_shared_mem_name);
    bool WriteTankStatusToMem(std::shared_ptr<TankStatus> IN stat, const std::string IN _shared_mem_name = m_shared_mem_name);
    bool CreateNewSharedMemAndWrite(std::shared_ptr<TankStatus> IN stat, const std::string IN _shared_mem_name = m_shared_mem_name);
    bool toggleSystemStart(const std::string IN _shared_mem_name = m_shared_mem_name);
    bool CheckSystemIsRunning(void);
    TankStatusFuncs(std::string _shared_mem_name){TankStatusFuncs::m_shared_mem_name = _shared_mem_name;m_mem_size = sizeof(real_tank_stat);};
};

#undef IN
#undef OUT


